﻿using System;

namespace CodeContrib
{
	public class RandomInteger : IRandom<int>
	{
		private readonly int _maximumValue;
		private readonly int _minimumValue;

		public int MaximumValue
		{
			get { return _maximumValue; }
		}

		public int MinimumValue
		{
			get { return _minimumValue; }
		}

		public RandomInteger() : this(int.MinValue, int.MaxValue)
		{
		}

		public RandomInteger(int maxValue) : this(int.MinValue, maxValue)
		{
		}

		public RandomInteger(int minValue, int maxValue)
		{
			if (minValue > maxValue)
			{
				throw new ArgumentOutOfRangeException("minValue", minValue, "'minValue' cannot be greater than 'maxValue'");
			}

			_maximumValue = maxValue;
			_minimumValue = minValue;
		}

		public int Next()
		{
			var random = RandomSingleton.Instance.Random;

			return random.Next(_minimumValue, _maximumValue);
		}
	}
}